package yja.gzw.app.activity

import android.util.Log
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.tabs.TabLayout
import yja.gzw.app.R
import yja.gzw.app.adapter.KaipiaoAdapter
import yja.gzw.app.adapter.MinxiAdapter
import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityKaipianguanliBinding
import yja.gzw.app.fragmentview.KaipiaoFragment
import yja.gzw.app.fragmentview.KaipiaoyiFragment
import yja.gzw.app.fragmentview.kaipiaozhongFragment
import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel

class KaipianguanliActivity :BaseActivity<Mainviewmodel, ActivityKaipianguanliBinding>(R.layout.activity_kaipianguanli){

  val tasslist= mutableListOf<String>("未开票","开票中","已开票")
    val listfragment= mutableListOf<Fragment>(
        KaipiaoFragment(), kaipiaozhongFragment(),KaipiaoyiFragment()
    )
    override fun initView() {

        binding.viewpager.adapter=object : FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {

                return listfragment.size

            }

            override fun getItem(position: Int): Fragment {

                return listfragment[position]

            }

            override fun getPageTitle(position: Int): CharSequence {
                return tasslist[position]
            }

        }

        binding.tabview.setupWithViewPager(binding.viewpager)





//            viewmodel.onkaipiaowang(UserData.token,mapOf("page" to "1","pagesize" to "10","status" to "0"))
//
//            binding.tabview.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
//                override fun onTabSelected(tab: TabLayout.Tab) {
//                        if(tab.position==0){
//                            viewmodel.onkaipiaowang(UserData.token,mapOf("page" to "1","pagesize" to "10","status" to "0"))
//
//                        }else if(tab.position==1){
//                            viewmodel.onkaipiaowang(UserData.token,mapOf("page" to "1","pagesize" to "10","status" to "1"))
//                        }else{
//                            viewmodel.onkaipiaowang(UserData.token,mapOf("page" to "1","pagesize" to "10","status" to "2"))
//                        }
//                }
//
//                override fun onTabUnselected(tab: TabLayout.Tab?) {
//
//                }
//
//                override fun onTabReselected(tab: TabLayout.Tab?) {
//
//                }
//
//            })



//        for (s in tasslist) {
//            val tabs= binding.tabview.newTab()
//           binding.tabview.addTab(tabs.setText(s))
//
//        }


    }

    override fun dataObservese() {
//        viewmodel.onkaipiao.observe(this, Observer {
//            if(it.code==1){
//             Log.e("开票管理",it.data.data.toString())
//                binding.review.layoutManager= LinearLayoutManager(this)
//                fabiada= KaipiaoAdapter(this,it.data.data)
//                binding.review.adapter= fabiada
//
//
//            }else{
//                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
//
//            }
//
//
//        })


    }
}